package com.project.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.project.entity.ProjectInfo;
import com.project.page.Page;
import com.project.service.ProjectInfoService;
import com.project.service.Impl.ProjectInfoServiceImpl;

public class ProjectInfoServlet extends HttpServlet {
	ProjectInfoService impl = new ProjectInfoServiceImpl();
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int pageNo = 0;
		if(request.getParameter("page") != null) {
			pageNo = Integer.parseInt(request.getParameter("page"));
		}else {
			pageNo = 1;
		}
		int totalCount = impl.getTotalCount();
		Page page = new Page(pageNo, 3, totalCount);
		int totalPageCount = page.getTotalPageCount();
		request.setAttribute("totalPageCount", totalPageCount);
		request.setAttribute("pageNo", pageNo);
		List<ProjectInfo> pros = impl.qureyAllByPage(page);
		request.setAttribute("pros", pros);
		request.getRequestDispatcher("query.jsp").forward(request, response);
	}
}
